let alpha = "abcdefghijklmnopqrstuvwxyz";

function encrypt(plaintext) {
    var t = plaintext.toLowerCase();
    var outt = "";
    var needseparator = false;
    for (var i = 0, len = t.length; i < len; i++) {
        var l = t[i];
        var idx = alpha.indexOf(l);
        if (-1 == idx) {
            outt += l;
            needseparator = false;
            return null
        } else {
            if (needseparator) outt += "-";
            outt += (idx + 1).toString();
            needseparator = true;
        }
    }
    return outt;
}

function decrypt(ciphertext) {
    var t = ciphertext.replace(/([\d]{1,2})([^\d]|$)/g, function (match, p1, p2) {
        return alpha[Number(p1) - 1] + (p2 == "-" ? "" : p2);
    });
    return t;
}

export default {
    encrypt,
    decrypt
}
